import 'package:get/get.dart';
import 'package:honeypotflutter/modules/hire/api/hireApi.dart';
import 'package:honeypotflutter/modules/hire/models/hire_param.dart';
import 'package:honeypotflutter/public/public_date.dart';
import '../../models/hire_empty_model.dart';
import '../../models/hire_rent_rent_model.dart';

class HireRentRentLogic extends GetxController {
  int smallSelectBox = 0;
  int middleSelectBox = 0;
  int maxSelectBox = 0;
  RxInt selectDay = RxInt(0);
  RxDouble countPrice = RxDouble(0.00);
  String startTime = "";

  late HireRentRentModel priceModel;
  late HireEmptyModel itemModel;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    startTime = HLDate.hl_format(type: DateType.YYMMDD);
  }

  /*
  * 计算几天前后
   */
  String calculateDate(int day) {
    final now = DateTime.now().add(Duration(days: day));
    return HLDate.hl_dateTimeToString(date: now, type: DateType.YYMMDD);
  }

  /*
  * 更新价格
  * */
  updateCountPrice() {
    double small = smallSelectBox * (priceModel.tmcDeviceFeeContractPriceS13 ?? 0.00);
    double middle = middleSelectBox * (priceModel.tmcDeviceFeeContractPriceS12 ?? 0.00);
    double max = maxSelectBox * (priceModel.tmcDeviceFeeContractPriceS11 ?? 0.00);
    countPrice.value = (small + middle + max) * selectDay.value * 1.0;
  }

  /*
  * 确认
  * */
  sureRent() async {
    HireParam param = HireParam();
    param.deviceId = this.itemModel.deviceId;
    param.buyDays = this.selectDay.value;
    param.totalFee = countPrice.value;
    param.cabinetNumberS13 = smallSelectBox;
    param.cabinetNumberS12 = middleSelectBox;
    param.cabinetNumberS11 = maxSelectBox;
    await HireApi.rent(param);
    Get.back<bool>(result: true);
  }
}
